#include <QStandardItemModel>
#include "PatientList.h"
#include "ui_PatientList.h"

PatientList::PatientList(QWidget *parent) :
	QWidget(parent),
	ui(new Ui::PatientList)
{
	ui->setupUi(this);

	connect(ui->tableView, SIGNAL(clicked(QModelIndex)), SLOT(SlotSelectedPatient(QModelIndex)));
}

PatientList::~PatientList()
{
	delete ui;
}

void PatientList::setPatientList(const QList<SPatient> &listPatient)
{
	QStandardItemModel *pModel = new QStandardItemModel;

	foreach (const SPatient &patient, listPatient)
	{
		pModel->appendRow(QList<QStandardItem*>()
						 << new QStandardItem(QString::number(patient.m_iID))
						 << new QStandardItem(patient.m_strChart)
						 << new QStandardItem(patient.m_strName)
						 << new QStandardItem(patient.m_dateBirth.toString(strDateFormat))
						 << new QStandardItem(patient.sexAge())
						 << new QStandardItem(patient.m_strPhone)
						 << new QStandardItem(patient.m_dateLastCapture.toString(strDateTimeFormat)));
	}

	pModel->setHeaderData(1, Qt::Horizontal, "등록번호");
	pModel->setHeaderData(2, Qt::Horizontal, "성명");
	pModel->setHeaderData(3, Qt::Horizontal, "생일");
	pModel->setHeaderData(4, Qt::Horizontal, "성별/나이");
	pModel->setHeaderData(5, Qt::Horizontal, "연락처");
	pModel->setHeaderData(6, Qt::Horizontal, "마지막 촬영일");
	ui->tableView->setModel(pModel);
	ui->tableView->horizontalHeader()->resizeSection(1, 101);
	ui->tableView->horizontalHeader()->resizeSection(2, 111);
	ui->tableView->horizontalHeader()->resizeSection(3, 131);
	ui->tableView->horizontalHeader()->resizeSection(4, 98);
	ui->tableView->horizontalHeader()->resizeSection(5, 172);
	ui->tableView->horizontalHeader()->setSectionHidden(0, true); //id 컬럼 숨김
	ui->tableView->resizeColumnsToContents();
}

void PatientList::SlotSelectedPatient(const QModelIndex &index)
{
	emit SignalSelectedPatient(index.sibling(index.row(), 0).data().toInt());
}
